<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MiXiM: BatteryStats Class Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">MiXiM
   &#160;<span id="projectnumber">2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00033.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pub-static-attribs">Static Public Attributes</a> &#124;
<a href="#pro-attribs">Protected Attributes</a> &#124;
<a href="#pri-methods">Private Member Functions</a>  </div>
  <div class="headertitle">
<div class="title">BatteryStats Class Reference<div class="ingroups"><a class="el" href="a00530.html">Power consumption - Classes using/defining power consumption</a></div></div>  </div>
</div>
<div class="contents">
<!-- doxytag: class="BatteryStats" --><!-- doxytag: inherits="BaseModule" -->
<p>collects and formates statistical data from the battery  
 <a href="a00033.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="a00484_source.html">BatteryStats.h</a>&gt;</code></p>
<div class="dynheader">
Inheritance diagram for BatteryStats:</div>
<div class="dyncontent">
<div class="center"><img src="a00609.png" border="0" usemap="#BatteryStats_inherit__map" alt="Inheritance graph"/></div>
<center><span class="legend">[<a target="top" href="graph_legend.html">legend</a>]</span></center></div>
<div class="dynheader">
Collaboration diagram for BatteryStats:</div>
<div class="dyncontent">
<div class="center"><img src="a00610.png" border="0" usemap="#BatteryStats_coll__map" alt="Collaboration graph"/></div>
<center><span class="legend">[<a target="top" href="graph_legend.html">legend</a>]</span></center></div>

<p><a href="a00611.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00033.html#a07bebc9788ff9ec28a8b4d3d1473d977">initialize</a> (int)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Basic initialization for all modules.  <a href="#a07bebc9788ff9ec28a8b4d3d1473d977"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aa5991c9ecc71e069e42f0496e5a1c37f"></a><!-- doxytag: member="BatteryStats::handleMessage" ref="aa5991c9ecc71e069e42f0496e5a1c37f" args="(cMessage *)" -->
virtual void&#160;</td><td class="memItemRight" valign="bottom"><b>handleMessage</b> (cMessage *)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a9fc9cb2cb11cc93cd22b9a3a5df33013"></a><!-- doxytag: member="BatteryStats::receiveSignal" ref="a9fc9cb2cb11cc93cd22b9a3a5df33013" args="(cComponent *source, simsignal_t signalID, cObject *obj)" -->
virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00033.html#a9fc9cb2cb11cc93cd22b9a3a5df33013">receiveSignal</a> (cComponent *source, simsignal_t signalID, cObject *obj)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Called by the signaling mechanism whenever a change of a category occurs to which we have subscribed. In this base class just handle the host state switching and some debug notifications. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a07c69e80cfcfe2df2d90f3bbbcaa7493"></a><!-- doxytag: member="BatteryStats::finish" ref="a07c69e80cfcfe2df2d90f3bbbcaa7493" args="()" -->
virtual void&#160;</td><td class="memItemRight" valign="bottom"><b>finish</b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00033.html#a659de266519b40fcc35e920b8c45408f">summary</a> (double, double, simtime_t_cref)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">invoked by the Battery Module's finish()  <a href="#a659de266519b40fcc35e920b8c45408f"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00033.html#a36927a49cf82b948194a84e595bc1db3">detail</a> (const <a class="el" href="a00084.html">DeviceEntry</a> *, int)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">invoked by the Battery Module's at finish()  <a href="#a36927a49cf82b948194a84e595bc1db3"></a><br/></td></tr>
<tr><td colspan="2"><h2><a name="pub-static-attribs"></a>
Static Public Attributes</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="adc69f67560c724bb41dbd4c5dfd81df0"></a><!-- doxytag: member="BatteryStats::catBatteryStateSignal" ref="adc69f67560c724bb41dbd4c5dfd81df0" args="" -->
static const <a class="el" href="a00201.html">simsignalwrap_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00033.html#adc69f67560c724bb41dbd4c5dfd81df0">catBatteryStateSignal</a> = <a class="el" href="a00201.html">simsignalwrap_t</a>( &quot;org.mixim.modules.power.battery.batterystate&quot; )</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight"><a class="el" href="a00192.html" title="The signal class stores the physical representation of the signal of an AirFrame.">Signal</a> for the <a class="el" href="a00033.html" title="collects and formates statistical data from the battery">BatteryStats</a>. <br/></td></tr>
<tr><td colspan="2"><h2><a name="pro-attribs"></a>
Protected Attributes</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a03ac20b06dbccee77e65191265682eaf"></a><!-- doxytag: member="BatteryStats::doDetail" ref="a03ac20b06dbccee77e65191265682eaf" args="" -->
int&#160;</td><td class="memItemRight" valign="bottom"><b>doDetail</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aaee44a254a029ec3ef5500c46ceb53dc"></a><!-- doxytag: member="BatteryStats::doTimeSeries" ref="aaee44a254a029ec3ef5500c46ceb53dc" args="" -->
int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00033.html#aaee44a254a029ec3ef5500c46ceb53dc">doTimeSeries</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Enable tracking of output vectors? <br/></td></tr>
<tr><td colspan="2"><div class="groupHeader">Tracked statistic values.</div></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a0743e048cf348ccb088f7fe63ce5eaf0"></a><!-- doxytag: member="BatteryStats::residualVec" ref="a0743e048cf348ccb088f7fe63ce5eaf0" args="" -->
cOutVector&#160;</td><td class="memItemRight" valign="bottom"><b>residualVec</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a64567e581be22366087716a23f4d9d20"></a><!-- doxytag: member="BatteryStats::relativeVec" ref="a64567e581be22366087716a23f4d9d20" args="" -->
cOutVector&#160;</td><td class="memItemRight" valign="bottom"><b>relativeVec</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a1c3254ee8dbc2c51c58598aa5fe208c9"></a><!-- doxytag: member="BatteryStats::estimateVec" ref="a1c3254ee8dbc2c51c58598aa5fe208c9" args="" -->
cOutVector&#160;</td><td class="memItemRight" valign="bottom"><b>estimateVec</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a7b1d7fe230c0aa033926faf32dbcc4d0"></a><!-- doxytag: member="BatteryStats::estimateRelVec" ref="a7b1d7fe230c0aa033926faf32dbcc4d0" args="" -->
cOutVector&#160;</td><td class="memItemRight" valign="bottom"><b>estimateRelVec</b></td></tr>
<tr><td colspan="2"><h2><a name="pri-methods"></a>
Private Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ab497aaa7286125376a409eb86ec9d4fb"></a><!-- doxytag: member="BatteryStats::BatteryStats" ref="ab497aaa7286125376a409eb86ec9d4fb" args="(const BatteryStats &amp;)" -->
&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00033.html#ab497aaa7286125376a409eb86ec9d4fb">BatteryStats</a> (const <a class="el" href="a00033.html">BatteryStats</a> &amp;)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Copy constructor is not allowed. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a110cd30b14b41a9452bad66bafff30c3"></a><!-- doxytag: member="BatteryStats::operator=" ref="a110cd30b14b41a9452bad66bafff30c3" args="(const BatteryStats &amp;)" -->
<a class="el" href="a00033.html">BatteryStats</a> &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00033.html#a110cd30b14b41a9452bad66bafff30c3">operator=</a> (const <a class="el" href="a00033.html">BatteryStats</a> &amp;)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Assignment operator is not allowed. <br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>collects and formates statistical data from the battery </p>
<p>See BatteryStats.ned for parameters</p>
<p>Generates time series information from <a class="el" href="a00032.html" title="residual capacity of battery">BatteryState</a> information published by the battery and by reading its s-o-c information (currently not interesting). Also generates summary statistics when the Battery module passes its <a class="el" href="a00084.html" title="per-device/per-account record of battery consumption, is passed to BatteryStats on finish()...">DeviceEntry</a> table at finish(). Note: only <a class="el" href="a00033.html" title="collects and formates statistical data from the battery">BatteryStats</a> modules should access <a class="el" href="a00032.html" title="residual capacity of battery">BatteryState</a> information, other modules should use Battery's estimateResidual method. </p>
</div><hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="a36927a49cf82b948194a84e595bc1db3"></a><!-- doxytag: member="BatteryStats::detail" ref="a36927a49cf82b948194a84e595bc1db3" args="(const DeviceEntry *, int)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void BatteryStats::detail </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="a00084.html">DeviceEntry</a> *&#160;</td>
          <td class="paramname"><em>devices</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>numDevices</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>invoked by the Battery Module's at finish() </p>
<p>(should not rely on BatteryStats::finish() to clean up resources </p>

<p>References <a class="el" href="a00084.html#a61a487c73b3bf0d58219cccfe793311c">DeviceEntry::accts</a>, and <a class="el" href="a00084.html#a9ee839aa662f60bea339e49fef4fb403">DeviceEntry::numAccts</a>.</p>
<div class="fragment"><pre class="fragment">{
  Enter_Method_Silent();
  <span class="keywordflow">if</span> (!doDetail)
    <span class="keywordflow">return</span>;

  recordScalar(<span class="stringliteral">&quot;num devices&quot;</span>, numDevices);

  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; numDevices; ++i){
    <span class="keywordtype">double</span> total = 0;
    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j &lt; devices[i].<a class="code" href="a00084.html#a9ee839aa662f60bea339e49fef4fb403" title="The amount of different power drawing activities/acounts this device has.">numAccts</a>; ++j) {
      total += devices[i].<a class="code" href="a00084.html#a61a487c73b3bf0d58219cccfe793311c" title="The power already drawn for each activity/account.">accts</a>[j];
    }
    recordScalar(devices[i].name.c_str(), i);
    recordScalar(<span class="stringliteral">&quot;device total (mWs)&quot;</span>, total);
    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j &lt; devices[i].<a class="code" href="a00084.html#a9ee839aa662f60bea339e49fef4fb403" title="The amount of different power drawing activities/acounts this device has.">numAccts</a>; ++j) {
      recordScalar(<span class="stringliteral">&quot;account&quot;</span>, j);
      recordScalar(<span class="stringliteral">&quot;energy (mWs)&quot;</span>, devices[i].accts[j]);
      recordScalar(<span class="stringliteral">&quot;time (s)&quot;</span>, devices[i].times[j]);
    }
  }
}
</pre></div>
</div>
</div>
<a class="anchor" id="a07bebc9788ff9ec28a8b4d3d1473d977"></a><!-- doxytag: member="BatteryStats::initialize" ref="a07bebc9788ff9ec28a8b4d3d1473d977" args="(int)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void BatteryStats::initialize </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>stage</em></td><td>)</td>
          <td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Basic initialization for all modules. </p>
<p>Subscription should be in stage==0, and firing notifications in stage==1 or later.</p>
<p>NOTE: You have to call this in the <a class="el" href="a00033.html#a07bebc9788ff9ec28a8b4d3d1473d977" title="Basic initialization for all modules.">initialize()</a> function of the inherited class! </p>

<p>Reimplemented from <a class="el" href="a00027.html#a03030e439aaf030c83da6e71e8be2f80">BaseModule</a>.</p>

<p>References <a class="el" href="a00033.html#adc69f67560c724bb41dbd4c5dfd81df0">catBatteryStateSignal</a>, <a class="el" href="a00033.html#aaee44a254a029ec3ef5500c46ceb53dc">doTimeSeries</a>, <a class="el" href="a00027.html#aabf0226159b22b46e70031fd3bb3b1b2">BaseModule::findHost()</a>, and <a class="el" href="a00201.html#aa01f017b96087bc252445206777e0080">simsignalwrap_t::initialize()</a>.</p>
<div class="fragment"><pre class="fragment">{
  <a class="code" href="a00033.html#a07bebc9788ff9ec28a8b4d3d1473d977" title="Basic initialization for all modules.">BaseModule::initialize</a>(stage);
  <span class="keywordflow">if</span> (stage==0) {
    doDetail = 0;
    doDetail = par(<span class="stringliteral">&quot;detail&quot;</span>).boolValue();
    debugEV &lt;&lt; <span class="stringliteral">&quot;show details = &quot;</span> &lt;&lt; doDetail &lt;&lt; endl;

    <a class="code" href="a00033.html#aaee44a254a029ec3ef5500c46ceb53dc" title="Enable tracking of output vectors?">doTimeSeries</a> = 0;
    <a class="code" href="a00033.html#aaee44a254a029ec3ef5500c46ceb53dc" title="Enable tracking of output vectors?">doTimeSeries</a> = par(<span class="stringliteral">&quot;timeSeries&quot;</span>).boolValue();
    debugEV &lt;&lt; <span class="stringliteral">&quot;show timeSeries = &quot;</span> &lt;&lt; <a class="code" href="a00033.html#aaee44a254a029ec3ef5500c46ceb53dc" title="Enable tracking of output vectors?">doTimeSeries</a> &lt;&lt; endl;

    <span class="keywordflow">if</span> (<a class="code" href="a00033.html#aaee44a254a029ec3ef5500c46ceb53dc" title="Enable tracking of output vectors?">doTimeSeries</a>) {
      <a class="code" href="a00027.html#aabf0226159b22b46e70031fd3bb3b1b2" title="Function to get a pointer to the host module.">findHost</a>()-&gt;subscribe(<a class="code" href="a00033.html#adc69f67560c724bb41dbd4c5dfd81df0" title="Signal for the BatteryStats.">catBatteryStateSignal</a>.<a class="code" href="a00201.html#aa01f017b96087bc252445206777e0080">initialize</a>(), <span class="keyword">this</span>);

      <span class="comment">// suggest enabling only residualVec (omnetpp.ini), unless</span>
      <span class="comment">// others are of interest</span>

      residualVec.setName(<span class="stringliteral">&quot;capacity&quot;</span>);
      residualVec.setUnit(<span class="stringliteral">&quot;mW-s&quot;</span>);
      relativeVec.setName(<span class="stringliteral">&quot;capacity(relative)&quot;</span>);

      estimateVec.setName(<span class="stringliteral">&quot;estimate&quot;</span>);
      estimateVec.setUnit(<span class="stringliteral">&quot;mW-s&quot;</span>);
      estimateRelVec.setName(<span class="stringliteral">&quot;estimate(relative)&quot;</span>);
    }
  }
}
</pre></div>
</div>
</div>
<a class="anchor" id="a659de266519b40fcc35e920b8c45408f"></a><!-- doxytag: member="BatteryStats::summary" ref="a659de266519b40fcc35e920b8c45408f" args="(double, double, simtime_t_cref)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void BatteryStats::summary </td>
          <td>(</td>
          <td class="paramtype">double&#160;</td>
          <td class="paramname"><em>init</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">double&#160;</td>
          <td class="paramname"><em>final</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">simtime_t_cref&#160;</td>
          <td class="paramname"><em>lifetime</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>invoked by the Battery Module's finish() </p>
<p>(should not rely on BatteryStats::finish() to clean up resources </p>
<div class="fragment"><pre class="fragment">{
  Enter_Method_Silent();
  recordScalar(<span class="stringliteral">&quot;nominal&quot;</span>, init, <span class="stringliteral">&quot;mW-s&quot;</span>);
  recordScalar(<span class="stringliteral">&quot;total&quot;</span>, init - <span class="keyword">final</span>, <span class="stringliteral">&quot;mW-s&quot;</span>);
  recordScalar(<span class="stringliteral">&quot;lifetime&quot;</span>, lifetime, <span class="stringliteral">&quot;s&quot;</span>);
  recordScalar(<span class="stringliteral">&quot;Mean power consumption&quot;</span>, (init - <span class="keyword">final</span>)/SIMTIME_DBL(simTime()), <span class="stringliteral">&quot;mW&quot;</span>);
}
</pre></div>
</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>D:/Projects/MiXiM/extsrc/mixim/src/modules/power/battery/<a class="el" href="a00484_source.html">BatteryStats.h</a></li>
<li>D:/Projects/MiXiM/extsrc/mixim/src/modules/power/battery/BatteryStats.cc</li>
</ul>
</div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="a00033.html">BatteryStats</a>      </li>

    <li class="footer">Generated on Tue Mar 5 2013 21:26:31 for MiXiM by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
